//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI;
using CommunityServer.Components;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;

namespace CommunityServer.Galleries.Controls
{
	/// <summary>
	/// Summary description for GallerySlideShow.
	/// </summary>
	public class SlideshowPro : GalleryBaseTemplatedWebControl
	{
		protected string PhotosDir;

		#region Child Controls
		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			InitializeChildControls();
		}


		private void InitializeChildControls()
		{
		}

		#endregion

		#region Event Overrides


		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			
			PhotosDir = SiteUrls.Instance().Locations["galleries"];
			
			if(!Page.IsPostBack)
				DataBind();
		}


		public override void DataBind()
		{
			base.DataBind();
			SetPageTitle();
		}


		public static string SlideshowPicturesPath()
		{
			CSContext cSContext = CSContext.Current;
			GalleryUrls galleryUrls = GalleryUrls.Instance();
			if(Globals.IsNullorEmpty(cSContext.ApplicationKey)) //All Galleries on the site
				return galleryUrls.SlideshowPictures();
			else if(cSContext.CategoryID > 0) //Just the current category
				return galleryUrls.SlideshowPictures(cSContext.ApplicationKey,cSContext.CategoryID);
			else //All categories in the current gallery
				return galleryUrls.SlideshowPictures(cSContext.ApplicationKey);
		}

		private void SetPageTitle()
		{
			CSContext cSContext = CSContext.Current;
			String pageTitle = ResourceManager.GetString("Gallery_SlideShow_SlideShow"); 
			if(Globals.IsNullorEmpty(cSContext.ApplicationKey)) //All Galleries on the site
				pageTitle = string.Format("{0} : {1}", pageTitle, ResourceManager.GetString("Gallery_SlideShow_AllGalleries"));
			else if(cSContext.CategoryID > 0) //Just the current category
			{
				Gallery g = Galleries.GetGallery(cSContext.ApplicationKey);
				pageTitle = string.Format("{0} : {1} : {2}", pageTitle, g.Name, PostCategories.GetCategory(cSContext.CategoryID, g.SectionID ).Name );
			}
			else //All categories in the current gallery
				pageTitle = string.Format("{0} : {1}", pageTitle, Galleries.GetGallery(cSContext.ApplicationKey).Name );

			Head.AddTitle(pageTitle, cSContext.Context);
		}

		#endregion


		/// <summary>
		/// All skins should be found in the skin directory and named after the control.
		/// </summary>
		protected override string ExternalSkinFileName
		{
			get { return (SkinFile == null) ? base.ExternalSkinFileName : string.Concat("Skins/", SkinFile); }
		}

		/// <summary>
		/// A property which allows skin designers to specify the skin file to use for the control.
		/// eg. This can allow for the same control to appear differently in a sidebar or main content area.
		/// It must be the full filename of a file in the current themes Skins/ folder.
		/// </summary>
		private string _skinfilename = null;
		public virtual string SkinFile
		{
			get {return _skinfilename;}
			set {_skinfilename = value;}
		}
		protected override bool LoadThemedControl()
		{
			if(this.Page != null && SkinFile != null)
			{
				string path = ThemeManager.Instance().SkinPath(this.ThemeName,ExternalSkinFileName);
				Control skin = this.Page.LoadControl( path );
				skin.ID="_";
				this.Controls.Add( skin );
				return true;
			}
			else
				return base.LoadThemedControl();

		}

	}
}
